package cn.tedu.lucky.draw.server.controller;

import cn.tedu.lucky.draw.server.common.annotation.OperationLog;
import cn.tedu.lucky.draw.server.common.result.JsonResult;
import cn.tedu.lucky.draw.server.protocol.po.Prize;
import cn.tedu.lucky.draw.server.protocol.query.PrizeQuery;
import cn.tedu.lucky.draw.server.service.IPrizeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

/**
 * 控制层-奖品
 */
@Slf4j
@RestController
@RequestMapping("")
@CrossOrigin
public class PrizeController {
    @Autowired
    private IPrizeService prizeService;

    /**
     * 查询所有奖品
     */
    @PostMapping("/draw/prize/findAll")
    public JsonResult<List<Prize>> findAll(@RequestBody PrizeQuery prizeQuery){
        log.debug(prizeQuery.toString());
        List<Prize> list = prizeService.findAll(prizeQuery);
        return JsonResult.ok(list);
    }

    /**
     * 新增奖品
     */
    @OperationLog(operation = "新增奖品")
    @PostMapping("/draw/prize/save")
    public JsonResult<Void> save(@RequestBody Prize prize){
        log.debug(prize.toString());
        prizeService.save(prize);
        return JsonResult.ok();
    }

    @GetMapping("/draw/prize/findPrize/{id}")
    public JsonResult<List<Prize>> findPrizeByActivityId(@PathVariable Long id){
        List<Prize> list = prizeService.findPrizeByActivityId(id);
        return JsonResult.ok(list);
    }

    @GetMapping("/draw/price/noBindPrize/{id}")
    public JsonResult<List<Prize>> findNoBindPrize(@PathVariable Long id){
        List<Prize> list = prizeService.findNoBindPrize(id);
        return JsonResult.ok(list);
    }

}
